<?php

/* @auther wf
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class ZTask {

    public $conn;

    public function __construct() {
        $this->conn = Yii::app()->db;
    }

    /**
     * 得到当前考试项目
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getExamAll($where = '') {
        $sql = ' SELECT * FROM "{{exam}}" WHERE "is_del"= 0 AND "exam_status" != 0 ' . $where . ' ORDER BY "time_created" DESC ';
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }

    /**
     * 得到所有人员作为负责人
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getUserAll() {
        $sql = ' SELECT "id","username" FROM "{{user}}" WHERE "id" > 0 AND "status" = 1';
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }

    /**
     * 得到所有管理员任务
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getTaskAll($serch) {

        $sql = ' SELECT "task_id","exam_id","user_id","task_name","task_status","task_expired" FROM "{{task}}" WHERE "task_id" > 0 ';
        $sqlcount = ' SELECT count(*) FROM "{{task}}" WHERE "task_id" > 0 ';
        $where = "";
        if (isset($serch['exam_id']) && $serch['exam_id'] > 0) {
            $where .= ' AND "exam_id" = ' . $serch['exam_id'];
        }
        if (isset($serch['user_id']) && $serch['user_id'] > 0) {
            $where .= ' AND "user_id" = ' . $serch['user_id'];
        }
        if (isset($serch['task_expired']) && !empty($serch['task_expired'])) {
            $where .= ' AND "task_expired" = ' . strtotime($serch['task_expired']);
        }
        if (isset($serch['task_status']) && $serch['task_status'] > 0) {
            $where .= ' AND "task_status" = ' . $serch['task_status'];
        }
        if (isset($serch['role_id']) && $serch['role_id'] > 0) {
            $where .= ' AND "user_id" IN ( SELECT "id" FROM "exm_user" WHERE "role_id" = ' . $serch['role_id'] . ') ';
        }
        $order = ' ORDER BY "time_created" DESC ';
        $data = ZCommon::getDaoPageList($sql . $where . $order, $sqlcount . $where . $order, 8);
        return $data;
    }

    /**
     * 得到单条考试项目详情
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getExamOne($exam_id,$where = '') {
        $wh = '';
        if($exam_id>0){
            $wh = ' WHERE "exam_id" = '.$exam_id;
        }elseif(!empty($where)){
            $wh = " WHERE ".$where;
        }
        $sql = ' SELECT "exam_id","exam_term_name" FROM "{{exam}}" '.$wh;
        $data = Yii::app()->db->createCommand($sql)->queryRow();
        return $data;
    }

    /**
     * 得到所有班级信息
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getclass() {
        $sql = ' SELECT "class_name" FROM "{{student}}" GROUP BY "class_name" ';
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }

    /**
     * 得到所有的数据表
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _gettable() {
        return array(
            'student' => '园区学生信息表',
            'teacher' => '阅卷教师信息表',
            'point' => '园区学生成绩表',
            'student_out_score' => '区外学生成绩表',
        );
    }

    /**
     * 得到所有全通规则设置
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getproblemrule($where = '') {
        $sql = ' SELECT * FROM "{{problemrule}}" '. $where;
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }

    /**
     * 得到所有导入规则
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getimportrule($where = '') {

        $sql = ' SELECT * FROM "{{importrule}}" WHERE 1=1 ' . $where;
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }

    /**
     * 得到所有导入规则详细
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
    static public function _getimportruledetail($where = '') {
        $sql = ' SELECT * FROM "{{importrule_detail}}" ' . $where;
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }

    /**
     * 得到所有汇总方式
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
   static  public function _getcollect_mode() {
        return array(
            '1' => '题型汇总',
            '2' => '题号汇总',
        );
    }

    /**
     * 得到所有题型选择
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
   static public function _getcollect_questions() {
        return array(
            '1' => '主观题',
            '2' => '客观题',
            '3' => '作文题',
        );
    }

    /**
     * 得到所有栏位包含小分题
     * @version 1.0
     * @date 2013-12-14
     * @author wf
     */
   static  public function _getcollect_question($id = '') {
        $sql = " SELECT question_name FROM {{point_info}} WHERE collect_question = " . $id;
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        $question_str = array();
        foreach ($data as $k => $v) {
            $question_str[] = $v['question_name'];
        }
        $question_str = implode(';', $question_str);
        return $question_str;
    }

    /*
     * 取所有角色
     */

   static public function _getAllrole() {
        $sql = ' SELECT "role_id","role_name" FROM "{{role}}" WHERE "role_id" > 0 ';
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }
    
    
 	/**
     * @ 验证搜索条件是否为空
     * @ yindebin
     * @ 2014-01-14
     */
    static function check_search($str){
    	if($str == '0' || !empty($str)){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    /**
     * @ 用户表单数据过滤
     * @ yindebin
     * @ 2014-01-16
     */
    static function dis_input($str){
    	if(is_array($str)){
    		foreach ($str as $k=>$v){
    			if(is_array($v)){
    				break;    				
    			}
    			$str[$k] = trim(self::replace_specialChar($v));
    		}
    	}else{
    			$str = trim(self::replace_specialChar($str));
    	}
    		return $str;
    }
	
    static function replace_specialChar($strParam){
	    //$regex = "/\/|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\=|\\\|\|/";
            $regex = "/\/|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\|\+|\{|\}|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\=|\\\|\|/";
	    return preg_replace($regex,"",$strParam);
	}
   
/**
     * @ 用户表单数据过滤
     * @ yindebin
     * @ 2014-01-16
     */
    static function dis_post($str){
    	if(is_array($str)){
    		foreach ($str as $k=>$v){
    			if(is_array($v)){
    				break;    				
    			}
    			$str[$k] = trim(strip_tags($v));
    		}
    	}else{
    			$str = trim(strip_tags($str));
    	}
    		return $str;
    }
	
	
    /**
     *  @ 过滤用户搜索条件
     *  @ yindebin
     *  @ 2014-01-16
     */
    static function dis_search($str){
    	if(is_array($str)){
    		foreach ($str as $k=>$v){
    			$str[$k] =   htmlspecialchars($v);
    		}
    	}else{
    			$str =  htmlspecialchars($str);
    		}
    		return $str;
    }
    
    
    /*
     * 获取科目对应的题型
     */
    static function _getAllquestionType($fid){
        $sql = ' SELECT "question_id","question_name" FROM "{{question_type}}" WHERE "is_del"= 0 AND "disabled"=1 AND "subject_id" = '.$fid;
        $data = Yii::app()->db->createCommand($sql)->queryAll();
        return $data;
    }
    
     static function _getOnequestionType($id){
        $sql = ' SELECT "question_id","question_name" FROM "{{question_type}}" WHERE "disabled"=1 AND "is_del"=0 AND "question_id" = '.$id;
        $data = Yii::app()->db->createCommand($sql)->queryRow();
        return $data;
    }
    

}

?>